Data compression encodes data (a.k.a. source data, raw data, or uncompressed data) by transforming the data into a form which is smaller than the untransformed data. Reducing the size of the data helps conserve resources such as disk storage space and transmission bandwidth. However, compressed data is often decompressed before use, and the processing resources needed for decompression can be expensive. Accordingly, data encoding schemes (a.k.a. compression techniques) may involve tradeoffs between factors such as the degree of compression, the amount of distortion (if any) created by compression, and the computational resources used to compress and uncompress the data.
Run-length encoding (RLE) is a particular kind of data compression, in which each run of identical data values is stored as a single copy of the data value plus a count, rather than as the original run. A run is a sequence of copies of a single value. For instance, raw data AABBBCAAAA would be stored as four runs, which can be represented as A2B3C1A4, or as (2,A),(3,B),(1,C),(4,A), for example. Raw data need not be text; it can be pixels, records, or any other digital data.
Run-length encoding does not necessarily compress data. The amount of compression (or expansion) actually caused by run-length encoding depends on how many runs there are in the raw data, and how long those runs are. Nonetheless, run-length encoding is used in various fields to compress pixel data, hard disk images, sparse matrices, and/or other raw data.